package com.ruoyi.buss.report.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.buss.report.mapper.ReportBldkLsbMapper;
import com.ruoyi.buss.report.domain.ReportBldkLsb;
import com.ruoyi.buss.report.service.IReportBldkLsbService;

/**
 * 贷款结构趋势－不良贷款Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class ReportBldkLsbServiceImpl implements IReportBldkLsbService 
{
    @Autowired
    private ReportBldkLsbMapper reportBldkLsbMapper;

    /**
     * 查询贷款结构趋势－不良贷款
     * 
     * @param sjrq 贷款结构趋势－不良贷款ID
     * @return 贷款结构趋势－不良贷款
     */
    @Override
    public ReportBldkLsb selectReportBldkLsbById(String sjrq)
    {
        return reportBldkLsbMapper.selectReportBldkLsbById(sjrq);
    }

    /**
     * 查询贷款结构趋势－不良贷款列表
     * 
     * @param reportBldkLsb 贷款结构趋势－不良贷款
     * @return 贷款结构趋势－不良贷款
     */
    @Override
    public List<ReportBldkLsb> selectReportBldkLsbList(ReportBldkLsb reportBldkLsb)
    {
        return reportBldkLsbMapper.selectReportBldkLsbList(reportBldkLsb);
    }

    /**
     * 新增贷款结构趋势－不良贷款
     * 
     * @param reportBldkLsb 贷款结构趋势－不良贷款
     * @return 结果
     */
    @Override
    public int insertReportBldkLsb(ReportBldkLsb reportBldkLsb)
    {
        return reportBldkLsbMapper.insertReportBldkLsb(reportBldkLsb);
    }

    /**
     * 修改贷款结构趋势－不良贷款
     * 
     * @param reportBldkLsb 贷款结构趋势－不良贷款
     * @return 结果
     */
    @Override
    public int updateReportBldkLsb(ReportBldkLsb reportBldkLsb)
    {
        return reportBldkLsbMapper.updateReportBldkLsb(reportBldkLsb);
    }

    /**
     * 批量删除贷款结构趋势－不良贷款
     * 
     * @param sjrqs 需要删除的贷款结构趋势－不良贷款ID
     * @return 结果
     */
    @Override
    public int deleteReportBldkLsbByIds(String[] sjrqs)
    {
        return reportBldkLsbMapper.deleteReportBldkLsbByIds(sjrqs);
    }

    /**
     * 删除贷款结构趋势－不良贷款信息
     * 
     * @param sjrq 贷款结构趋势－不良贷款ID
     * @return 结果
     */
    @Override
    public int deleteReportBldkLsbById(String sjrq)
    {
        return reportBldkLsbMapper.deleteReportBldkLsbById(sjrq);
    }

    @Override
    public List<ReportBldkLsb> bldkList(ReportBldkLsb reportBldkLsb, LoginUser userInfo) {
        List<ReportBldkLsb> doList = new ArrayList<ReportBldkLsb>();
 
        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportBldkLsb.getSjrq())) {

            if ("9999".equals(reportBldkLsb.getSjrq())) {
                reportBldkLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportBldkLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportBldkLsb.setSjrqs(sjrqs);
        doList = reportBldkLsbMapper.bldk(reportBldkLsb);
        
        return doList;
    }

    @Override
    public List<ReportBldkLsb> bldkhz(ReportBldkLsb reportBldkLsb, LoginUser userInfo) {
        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportBldkLsb.getSjrq())) {
            if ("9999".equals(reportBldkLsb.getSjrq())) {
                reportBldkLsb.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportBldkLsb.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportBldkLsb.setSjrqs(sjrqs);
        List<ReportBldkLsb> doList = reportBldkLsbMapper.bldkze(reportBldkLsb);
        return doList;
    }
}
